home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0151.ZIP / CUTEFONE.C < prev    next >
C/C++ Source or Header  |  1984-10-05  |  2KB  |  98 lines

  1.  
  2. char linebuf[80];
  3.  
  4. char phonenum[80];        /* number string entered */
  5.  
  6. char letters[][3] = {
  7.  
  8.     '-','-','-',    /* 0 easy indexing */
  9.     '-','-','-',    /* 1 easy indexing */
  10.     'a','b','c',    /* 2 */
  11.     'd','e','f',    /* 3 */
  12.     'g','h','i',    /* 4 */
  13.     'j','k','l',    /* 5 */
  14.     'm','n','o',    /* 6 */
  15.     'p','r','s',    /* 7 */
  16.     't','u','v',    /* 8 */
  17.     'w','x','y'    /* 9 */
  18. };
  19.  
  20. int ctrs[10];        /* counters for each digit */
  21. int digits;        /* number of digits */
  22. int vowels;
  23. int cons_in_a_row;
  24. main () {
  25.  
  26. char *cp,*sp;
  27. int carry;        /* carry past last digit */
  28. char word[80];
  29. int i;
  30. char c;
  31.  
  32.     printf("Make word out of a phone number. T. Jennings 6 Oct 84\r\n");
  33.     printf("\r\n");
  34.     printf("The rules here are, you enter a string of digits, and you \r\n");
  35.     printf("get a list of sort-of words, which you have to wade through\r\n");
  36.     printf("to find real words. The more digits you enter, the more words.\r\n");
  37.     printf("Numbers that contain '0' or '1' cannot be used, since there are\r\n");
  38.     printf("no letters for those digits. (Look at your phone.) Words\r\n");
  39.     printf("that have no vowels, or four or more consonants in a row\r\n");
  40.     printf("are not displayed.\r\n");
  41.  
  42.     printf("Your number please: "); 
  43.     if (getstring(linebuf) == 0) return;
  44.     printf("\r\n");
  45.  
  46.     digits= 0;
  47.     cp= linebuf; sp= phonenum;
  48.     while (*cp) {
  49.         if ((*cp == '0') || (*cp == '1')) {
  50.             printf("Cant use 0 or 1\r\n");
  51.             return;
  52.         }
  53.         if (isdigit(*cp)) {
  54.             *sp++= *cp;
  55.             ++digits;
  56.         }
  57.         ++cp;
  58.     }
  59.     *sp= '\0';
  60.     if (digits < 1) {
  61.         printf("you didnt enter any digits!\r\n");
  62.         return;
  63.     }
  64.     if (digits > 10) {
  65.         printf("Too many digits!\r\n");
  66.         return;
  67.     }
  68.  
  69.     printf("The number is %s\r\n",phonenum);
  70.  
  71.     carry= 0;
  72.     while (! carry) {
  73.  
  74.         sp= word;
  75.         vowels= 0;
  76.         cons_in_a_row= 0;
  77.         for (i= 0; i < digits; i++) {
  78.             c= letters[phonenum[i] - '0'] [ctrs[i]];
  79.             if ((c == 'a') || (c == 'e') || (c == 'i') ||
  80.               (c == 'o') || (c == 'u')) {
  81.                 ++vowels;
  82.                 cons_in_a_row= 0;
  83.  
  84.             } else if (++cons_in_a_row > 3) break;
  85.             *sp++= c;
  86.         }
  87.         *sp= '\0';
  88.  
  89.         if (vowels && (cons_in_a_row <= 3)) printf(" %s\r\n",word);
  90.  
  91.         for (i= 0; i < digits; i++) {
  92.             if (++ctrs[i] < 3) break;
  93.             ctrs[i]= 0;
  94.         }
  95.         if (i >= digits) ++carry;
  96.     }
  97. }
  98.